package com.tycmc.signelectroniccontracts.tools.store;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

import com.tycmc.signelectroniccontracts.tools.base.BaseApplication;
import com.tycmc.signelectroniccontracts.tools.manager.AppManager;


/**
 * Created by Administrator on 2016/11/9 0009.
 */

public class SharePre {
    /**
     * 返回shareprefeerences对象
     *
     * @return
     */
    public static SharedPreferences getSharePre() {
        Activity activity = AppManager.getAppManager().currentActivity();
        if (activity != null) {

            return activity.getSharedPreferences("chatDemo", Context.MODE_PRIVATE);
        }
        return new BaseApplication().getSharedPreferences("chatDemo", Context.MODE_PRIVATE);
    }

    public static SharedPreferences.Editor getEditor() {
        return getSharePre().edit();
    }

    /**
     * 读取shareperferences中的string值
     *
     * @param key
     * @param defalut 默认值
     * @return
     */
    public static String getString(String key, String defalut) {
        return getSharePre().getString(key, defalut);
    }

    /**
     * 读取整形
     *
     * @param key
     * @param defalut
     * @return
     */
    public static int getInt(String key, int defalut) {
        return getSharePre().getInt(key, defalut);
    }

    /**
     * 读取长整形
     *
     * @param key
     * @param defalut
     * @return
     */
    public static long getLong(String key, long defalut) {
        return getSharePre().getLong(key, defalut);
    }

    /**
     * 读取布尔型
     *
     * @param key
     * @param defalut
     * @return
     */
    public static boolean getBoolean(String key, boolean defalut) {
        return getSharePre().getBoolean(key, defalut);
    }

}
